package cn.sc.allinpay.allfavour.business.checktrans;

import android.os.Bundle;
import android.support.v7.widget.AppCompatSpinner;
import android.support.v7.widget.AppCompatTextView;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.AdapterView;

import java.util.List;

import butterknife.BindView;
import cn.sc.allinpay.allfavour.R;
import cn.sc.allinpay.allfavour.base.activity.BaseActivity;
import cn.sc.allinpay.allfavour.base.widget.DecorationVert;
import cn.sc.allinpay.allfavour.business.common.adapter.CheckTransAdapter;
import cn.sc.allinpay.allfavour.business.common.data.CheckCouponsRecord;


/**
 * activity 验券流水
 * author：pany
 * on 2017/12/1 11:14
 */
public class CheckTransActivity extends BaseActivity<CheckTransContract.View, CheckTransContract.Presenter>
        implements CheckTransContract.View, AdapterView.OnItemSelectedListener {

    @BindView(R.id.tvPromt)
    AppCompatTextView tvPromt;
    @BindView(R.id.spDate)
    AppCompatSpinner spDate;
    @BindView(R.id.recycler)
    RecyclerView recycler;

    private CheckTransAdapter transAdapter;

    @Override
    protected int layoutId() {
        return R.layout.activity_check_trans;
    }

    @Override
    protected void layoutTitle(View top, AppCompatTextView left, AppCompatTextView title, AppCompatTextView right) {
        title.setText("验券流水");
    }

    @Override
    protected CheckTransContract.Presenter bindPresenter() {
        return new CheckTransPresenter();
    }

    @Override
    protected void layoutContent(Bundle savedInstanceState) {
        spDate.setOnItemSelectedListener(this);
        recycler.addItemDecoration(new DecorationVert(this, R.dimen.margin_common, R.dimen.margin_common));
        recycler.setLayoutManager(new LinearLayoutManager(this));// 列表布局
        transAdapter = new CheckTransAdapter();
        transAdapter.setOnCheckAdapterListener(new CheckTransAdapter.OnCheckAdapterListener() {
            @Override
            public void onItempPrint(View view, int position, CheckCouponsRecord data) {
                presenter.reprint(data);
            }

            @Override
            public void onItemClick(View view, int position, Object data) {

            }
        });
        recycler.setAdapter(transAdapter);
    }


    @Override
    public void transAdapterChange(List<CheckCouponsRecord> datas) {
        transAdapter.change(datas);
    }

    @Override
    public void transAdapterClean() {
        transAdapter.clean();
    }

    @Override
    public int getDate() {
        return spDate.getSelectedItemPosition();
    }

    @Override
    public void showPromt(int visib, String text) {
        tvPromt.setVisibility(visib);
        tvPromt.setText(text);
    }

    @Override
    public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
        presenter.queryTransRecords();
    }

    @Override
    public void onNothingSelected(AdapterView<?> adapterView) {

    }
}
